-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernize to TypeScript #6
Conversation
Co-authored-by: José Luis Millán <[email protected]>
NOTE: I suggest we don't merge this (or at least we don't release a new version) until tests are added and CI jobs running those tests in different archs and Node versions. Note for example that the previous |
Makes sense. |
When I said that we should add tests here I meant "We The Team". |
Yep, I'm currently working on few unpopular and time consuming tasks. I may jump here when I find the time. BTW, if tests and CI was a blocker, IMHO it should have been done before this PR to avoid this block. |
Did you notice that this lib was using the server.bind() and server.listen() incorrectly and maybe it was not binding in the wrongly given second address argument or maybe it worked by accident? I'll confirm that later and comment here. |
So code in master branch looks like follows in TCPconst net = require('net');
const server = net.createServer();
const port = 1234;
const ip = '127.0.0.1';
server.listen({ port, exclusive: true }, ip, () => console.log('done')); Let's run it, let it running and check port 1234 usages in the system:
You see? It's listening in TCP UDPconst dgram = require('dgram');
const server = dgram.createSocket('udp4');
const port = 1234;
const ip = '127.0.0.1';
server.bind({ port, exclusive: true }, ip, () => console.log('done')); Let's run it, let it running and check port 1234 usages in the system:
You see? It's binding in UDP Why?Because the API usage is wrong.
|
Now let's try with the fixed code in this PR: TCPimport * as net from 'node:net';
const server = net.createServer();
const port = 1234;
const ip = '127.0.0.1';
server.listen({ port, host: ip, exclusive: true }, () => console.log('done'));
UDPimport * as dgram from 'node:dgram';
const server = dgram.createSocket('udp4');
const port = 1234;
const ip = '127.0.0.1';
server.bind({ port, address: ip, exclusive: true }, () => console.log('done'));
|
Tests (WIP, wanna add more) and CI job added: https://github.com/ibc/pick-port/actions/runs/7462140637 |
We should start using native Node tests rather than Jest. I think the changes needed here would be very minimal. |
We want this library to work with Node 16 or at least Node 18. |
Users may run an old Node version. It's just tests which would require a newer one. 99% of users won't run the tests, and the remaining 1% would have to use a newer Node to do it. I'm not blocking this PR (it's already approved), but the earlier we start porting tests to Node, the less painful it will be. |
We want that tests run in CI hosts using different Node versions, otherwise the purpose of tests is useless considering that we want to support Node >= 16 as declared in package.json. |
Fair enough. |
Details
ip
given topickPort()
was always ignored so default "0.0.0.0" was always used.